	var _lat;
	var _lng;
	var _city;
	function getCurrentAddress() {
		_lat = $("#hiddenLat").val();
		_lng = $("#hiddenLng").val();
		if (_lat && _lng) {

			getLocation(_lat, _lng);
		} else {
			$('.loading').css('display', 'inline-block');
			navigator.geolocation.getCurrentPosition(function(position) {
				_lat = position.coords.latitude;
				_lng = position.coords.longitude;
				$("#hiddenLng").val(_lng);
				$("#hiddenLat").val(_lat);
				getConvertLatLng(_lat, _lng);
			}, function(error) {
				switch (error.code) {
				case error.TIMEOUT:
					var msg="获取位置超时！您可通过点击消息界面【左下角键盘按钮】，打开【+】按钮，点击【位置】按钮，手动发送您当前位置！";
					$.confirm({'title': '提示','message'	: msg,'buttons':{'确定':{'class':'blue','action': function(){}}}});
					break;
				case error.PERMISSION_DENIED:
					var msg="您拒绝了使用位置共享服务，查询已取消！";
					$.confirm({'title': '提示','message'	: msg,'buttons':{'确定':{'class':'blue','action': function(){}}}});
					break;
				case error.POSITION_UNAVAILABLE:
					var msg="获取位置失败！您可通过点击消息界面【左下角键盘按钮】，打开【+】按钮，点击【位置】按钮，手动发送您当前位置！";
					$.confirm({'title': '提示','message'	: msg,'buttons':{'确定':{'class':'blue','action': function(){}}}});
					break;
				}
			}, {
				maximumAge : 10000,
				timeout : 10000,
				enableHighAccuracy : true
			});
		}
	}

	function getConvertLatLng(lat, lng){
		$.getJSON("../gpsparse.jsp", { lat: lat, lng: lng }, function (data) {
                if (data.error == 0){
                    $("#hiddenbLng").val(data.lng);
				    $("#hiddenbLat").val(data.lat);
				     getLocation(data.lat, data.lng);
                } else {
                    alert("获取数据失败!");
                }
            });
	}

	function getLocation(lat, lng) {
	/*
		$.ajax( {
			url : "getLocation.do?t=" +getts(),
			dataType : "json",
		type : 'post',
			data : {
				lat : lat,
				lng : lng
			},
		success : function(data) {
					if (data.status == 0) {
						_city = data.result.addressComponent.city;//将电池的城市赋值
						$('#hiddenProvince').val(data.result.addressComponent.province);
						$('#hiddenCity').val(_city);
					var addr=data.result.formatted_address;
						//addr=addr.replace('中国','');
						$('.address').val(addr);
						$('#hiddenTown').val(data.result.addressComponent.district);
						getCheXingByCity(_city);
			        } else {alert("定位失败");}
		     }
		});

		$.ajax( {
			//url : "getLocationByGgLatlng.do?lat="+lat+"&lng="+lng+"&t=" + (new Date()),
url : "http://maps.google.com/maps/api/geocode/json?latlng="+lat+","+lng+"&language=zh-CN&sensor=true",
			dataType : "json",
			type : 'get',
			success : function(data) {
				if(data.results.length>0){
					var first=data.results[0];
					var addr=first.formatted_address;
			        $('.address').val(addr); 
			        var address_components=first.address_components;
					$("#hiddenProvince").val("");
					$("#hiddenCity").val("");
					$("#hiddenTown").val("");
					for(k=0;k<address_components.length;k++){
						var p1=address_components[k].types[0];
						var p2=address_components[k].types[1];
						if("administrative_area_level_1"==p1&&"political"==p2){
							$("#hiddenProvince").val(address_components[k].short_name);
						}else if("locality"==p1&&"political"==p2){
							$("#hiddenCity").val(address_components[k].short_name);
							_city = address_components[k].short_name;//将电池的城市赋值
			                $('#city').html(address_components[k].short_name);
						}else if("sublocality"==p1&&"political"==p2){
							$("#hiddenTown").val(address_components[k].short_name);
						}
					}
			        getCheXingByCity(_city);
				}else{
					 alert("定位失败");
				}
			}
		});
		*/
        $.ajax( {
            url : "getLocationByGaodeLatlng.do?lng="+lng+"&lat="+lat,
            //url : "http://restapi.amap.com/v3/geocode/regeo?key=e4e68a5cf6df32793a5c7f00e7d17253&radius=500&location="+lng+","+lat,
            dataType : "json",
            type : 'get',
            success : function(data) {
                if (data.status =="1") {
                        var first=data.regeocode;
                        var addr=first.formatted_address;
                        var address_components=first.addressComponent;
                        $("#hiddenProvince").val(address_components.province);
                        if(address_components.city.length==0){
                            _city = address_components.province;
                            //将电池的城市赋值
                            if(null!=address_components.district&&address_components.district!=""){
                                _city =address_components.district;//针对省辖市
                            }
                        }else{
                            _city = address_components.city;//将电池的城市赋值
                        }
                        $("#m_city").val(_city);
                        $('#hiddenCity').val(_city);
                        
                        if(null!=address_components.district&&address_components.district!=""){
                            $("#hiddenTown").val(address_components.district);
                        }else{
                            $("#hiddenTown").val("市辖区");
                        }
                        getCheXingByCity(_city);
                }
                else {location.reload();}
            }
        });
    }
function getCheXingByCity(city) {
	if (city) {
		$.ajax( {
					url : 'ajaxQueryChexByCity.do?t=' + getts(),
					type : 'post',
					data : {
						'city' : city
					},
					dataType : 'json',
					success : function(data) {
						if (data.length > 0) {
							var html = "";
							for ( var i = 0; i < data.length; i = i + 1) {
								var timage='${pageContext.request.contextPath}/bettery/img/category.jpg';
								var bg='i-bg-red';
								var j=i%4;
								var k=i%2;
								if(j==1){
									bg='i-bg-blue';
								}
								if(j==2){
									bg='i-bg-purple';
								}
								if(j==3){
									bg='i-bg-green';
								}
								html+='<div class="module">';
								html+='<section class="i-banner"  onclick="queryDianchi('+data[i].id+',\''+data[i].name+'\');">';
								if(0==k){
									html+='	<div class="i-banner-title '+bg+'">';
									html+='		<span></span><span></span><h3>'+data[i].name+'</h3>';
									html+='	</div>';
									html+='	<div class="i-banner-pic">';
									if(data[i].imageUrl){timage=data[i].imageUrl;}
									html+='	<img   src="../bettery/img/loading.gif" xSrc="'+timage+'">';
									html+='	</div>';
								}else{
									html+='	<div class="i-banner-pic">';
									if(data[i].imageUrl){timage=data[i].imageUrl;}
									html+='	<img   src="../bettery/img/loading.gif"  xSrc="'+timage+'">';
									html+='	</div>';
									html+='	<div class="i-banner-title '+bg+'">';
									html+='		<label ></label><label ></label><h3>'+data[i].name+'</h3>';
									html+='	</div>';
								}
								html+='</section>';
								html+='</div>';
							}
							hideLoading();
							$('#category-list').html(html);
							scrollLoad();
							
						} else {
							alert('加载车型失败：' + data.message);
						}
					}
				});
	} else {
		alert('不能确定当前城市');
	}
}
function queryDianchi(id,name){
	if(id){
		$("#chexingId").val(id);
		$("#tsss").val(new Date());
		$("#hiddenChexingName").val(name);
		$("#dingDanForm1").submit();
	}
}
